package com.hulk.ratel.web.control;


import com.hulk.ratel.api.web.InitiativeScanPayService;
import com.hulk.ratel.api.web.dto.InitiativeScanPayReqDTO;
import com.hulk.ratel.api.web.dto.InitiativeScanPayRespDTO;
import com.hulk.ratel.web.control.basic.AbsBaseCtl;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;


/**
 * @Author: hulk
 * @E-mail: 29572320@qq.com
 * @Date: Create in 2018/8/31 下午10:14
 * @Version: 1.0.0
 * @Modify by:
 * Class description  主扫支付交易入口，报文解析和check
 */
@Slf4j
@AllArgsConstructor
@RestController
@RequestMapping(value = "/api/v1")
public class InitiativeScanPayCtl extends AbsBaseCtl {


    private InitiativeScanPayService payService;


    @PostMapping(value = "/INITIATIVE_SCANPAY", produces = {MediaType.APPLICATION_JSON_VALUE}, consumes = {MediaType.APPLICATION_FORM_URLENCODED_VALUE})
    @ResponseBody
    @Override
    public String excute(@RequestAttribute String partnerNo, @RequestAttribute String traceId,
                         @RequestAttribute String plainText, @RequestAttribute String partnerAESKey,
                         @RequestAttribute String intCutDate, @RequestAttribute String workId) {

        log.info("InitiativeScanPayController<主扫> 请求参数：workId:{}, partnerNo:{},traceId:{},plainText:{}.", new Object[]{workId, partnerNo, traceId, plainText});

        //解析报文并check
        InitiativeScanPayReqDTO  reqDTO = this.preHandle(plainText, traceId, null, InitiativeScanPayReqDTO.class);
         //支付业务处理
        InitiativeScanPayRespDTO respDTO = payService.excute(reqDTO,intCutDate,workId);

        //组装返回报文
        return this.postHandle(respDTO, partnerAESKey, partnerNo, workId);
    }




}